package com.ray.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.ray.bean.TableColumnConfig;
import com.ray.mapper.TableColumnConfigMapper;

@Service
public class TableColumnConfigService {
	@Autowired
	TableColumnConfigMapper columnConfigMapper;
	
	public TableColumnConfig getConfigByName(Map<String,Object> map) {
		Assert.notNull(map.get("loginCompanyId"),"公司id为空");
		Assert.notNull(map.get("tableName"),"表格名称为空");
		TableColumnConfig param = new TableColumnConfig(map);
		TableColumnConfig config = columnConfigMapper.getTableColumnConfigByName(param);
		return config;
	}
	
	public void saveConfig(Map<String,Object> map) {
		Assert.notNull(map.get("tableName"),"表格名称为空");
		TableColumnConfig param = new TableColumnConfig(map);
		TableColumnConfig config = columnConfigMapper.getTableColumnConfigByName(param);
		if (config == null) {
			int row = columnConfigMapper.addTableColumnConfig(param);
			Assert.isTrue(row>0, "保存表格显示列配置失败");
		} else {
			columnConfigMapper.updateTableColumnConfig(param);
		}
	}
}
